/**
  ******************************************************************************
  * @author     Chris
  * @since      2023/9/29 22:38
  *
  * @file       hd_key.c
  * @brief      KEY Hardware Driver.
  *
  * @note       This file contains the hardware driver for the KEY.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date           Author       Notes
  *   2023-09-29     Chris        the first version
  *
  ******************************************************************************
  */

#include "delay.h"
#include "stm32g4xx_ll_gpio.h"
#include "pd_h_gpio.h"


/** region Declaration and Definition Region */


/** region Variables and Constants Region */

/** endregion Variables and Constants Region */


/** region Function Declaration Region */

/** endregion Function Declaration Region */


/** endregion Declaration and Definition Region */



/** region Public Definition Region */
/**
 * @brief   按键初始化
 * @note    这里的按键接 PA0，触发后电平拉高。
 * @param   无
 * @retval  无
 */
void HD_KEY_Init(void) {
    PD_H_GPIO_KeyInit();
}

/**
 * @brief   获取按键返回值
 * @note    无
 * @param   无
 * @retval  0，按键弹起；1，按键按下。
 */
uint8_t HD_KEY_GetNum(void) {
    uint8_t keyNum = 0;

    if (PD_H_GPIO_ReadBit(GPIOA, LL_GPIO_PIN_0) == SET) {
        delay_ms(20);
        while (PD_H_GPIO_ReadBit(GPIOA, LL_GPIO_PIN_0));    // 等待按键松手
        delay_ms(20);
        keyNum = 1;
    }

    return keyNum;
}

/** endregion Public Definition Region */



/** region Private Definition Region */

/** endregion  Private Definition Region  */
